package com.gx.components.motor2
{
	import com.gx.core.Component;
	import com.gx.interfaces.IPhysicsLayer;
	
	import de.polygonal.motor2.World;
	import de.polygonal.motor2.math.AABB2;
	
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class PhysicsLayerM2 extends Component implements IPhysicsLayer
	{
		public var world:World;
		public var bounds:Rectangle;
		public var doSleep:Boolean;
		
		public function PhysicsLayerM2()
		{
			
			super();
		}
		
		override public function init():void
		{
			var aabb:AABB2 = new AABB2(bounds.x, bounds.y, bounds.width-bounds.x, bounds.height-bounds.y);
			world = new World(aabb, doSleep);
			World.doWarmStarting;
			World.doPositionCorrection;
			if(gravity != null)
			{
				this.gravity = gravity;
			}
		}
		
		public function step(dt:Number, iterations:int):void
		{
			world.step(dt, iterations);
		}
		
		private var _priority:int=0;
		public function get priority():int { return _priority; }
		public function set priority(value:int):void{_priority = value;}
		
		public function get gravity():Point { return new Point(world.gravity.x, world.gravity.y); }
		public function set gravity(value:Point):void{world.gravity.x = value.x;world.gravity.y=value.y}
		
	}
}